package com.tanhua.server.controller;


import com.tanhua.server.interceptor.NoAuthorization;
import com.tanhua.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;

@RequestMapping("/user")
@RestController
public class LoginController {

    @Autowired
    private UserService userService;


    /**
     * 发送验证码接口
     */
    @PostMapping("login")
    @NoAuthorization
    public ResponseEntity<Object> sendCheckCode(@RequestBody Map<String,Object> param){
        String phone = String.valueOf(param.get("phone"));
        return userService.sendCheckCode(phone);
    }


    /**
     * 验证短信，并登录
     */
    @PostMapping("/loginVerification")
    @NoAuthorization
    public ResponseEntity<Object> login(@RequestBody Map<String,String> param){

        String mobile = param.get("phone");

        String code = param.get("verificationCode");

        return userService.login(mobile,code);
    }
}
